package cn.com.callback

import cn.com.elite.EliteBean
import cn.com.elite.Util
import cn.com.kh.KHUtil
import cn.com.kh.getProperty
import cn.com.kh.hst.ThreeDesUtil
import com.huasheng.passwordencrypt.DecryptUtil
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.json.JSONException
import org.springframework.jdbc.core.JdbcTemplate

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 *
 * @Title: apiMPlusCustSync 同步(补录)单个或全量客户信息
 *
 */

public class apiMPlusCustSync implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(apiMPlusCustSync.class);

    private static final String appid = getProperty.get("appid");
    private static final String appsecret = getProperty.get("appsecret");
    private static final String doURL_Domain = getProperty.get("HSTURL");

    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {

        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        long startTime = System.currentTimeMillis();

        JSONObject outData = JSONObject.fromObject("{\"code\":1,\"message\":\"操作成功\"}");
        String getMethod = request.getMethod();
        log.debug("同步(补录)单个或全量客户信息 getMethod:" + getMethod);

        // 获取所有Header
        Map<String, String> mapHeader = new HashMap<String, String>();
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = request.getHeader(key);
            log.debug("同步(补录)单个或全量客户信息 Header-" + key + ":" + value);

            mapHeader.put(key, value);
        }

        // 获取数据源
        JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());

        // 获取调用数据
        String optype = request.getParameter("optype");
        log.info("同步(补录)单个或全量客户信息 请求参数：" + optype);

        String opJson = Util.getRequestBody(request, "UTF-8");
        log.info("同步(补录)单个或全量客户信息 请求Body：" + opJson);

        try {
            if (optype.equals("CUST")) {
                outData = doCust_One(jt, opJson);

            } else if (optype.equals("HIS")) {
                outData = doCust_History(jt, opJson);

            } else {
                outData.put("code", -1);
                outData.put("message", "不支持的操作类型optype:" + optype);
            }

        } catch (Exception e) {
            outData.put("code", -2);
            outData.put("message", "HTTP请求调用错误(" + e.getMessage() + "),请稍后再试!");
            log.error(outData, e);

        }
        log.debug("同步(补录)单个或全量客户信息 返回:" + outData.toString());
        return outData.toString();

    }

    // 同步(补录)单个客户信息
    public static JSONObject doCust_One(JdbcTemplate jt, String inJson) {

        JSONObject reJson = new JSONObject();

        try {
            // 调用处理信息
            JSONObject inObject = JSONObject.fromObject(inJson);

            // 解析调用参数
            String token = KHUtil.GetSFJV(inObject, "token");//token
            String hsNo = KHUtil.GetSFJV(inObject, "hsNo");//华盛号

            if (KHUtil.isNull(hsNo) || KHUtil.isNull(token)) {
                log.debug("doCust_One 接口入参为空:" + inObject);
                String outData = "{\"code\":\"-1\",\"message\":\"接口入参为空\"}";
                return JSONObject.fromObject(outData);
            }
            log.debug("doCust_One 解析信息-" + "hsNo: " + hsNo + "token: " + token);

            String sign_time = String.valueOf(System.currentTimeMillis());
            log.debug("doCust_One 解析信息-" + "sign_time: " + sign_time);

            HashMap<String, String> paramHashMap = new HashMap<String, String>();
            paramHashMap.put("token", token);
            paramHashMap.put("sign_time", sign_time);
            paramHashMap.put("hsNo", hsNo);

            log.debug("doCust_One paramHashMap：" + paramHashMap);
            //自然排序 升序参数
            String signfront = ThreeDesUtil.sortMap(paramHashMap, appid, appsecret);
            log.debug("doCust_One sign加密MD5前：" + signfront);
            String signafter = Util.getMD5Str(signfront);
            log.debug("doCust_One sign加密MD5后：" + signafter);

            //拼接接口入参
            paramHashMap.put("client_key", appid);
            paramHashMap.put("sign", signafter);

            String callJson = ThreeDesUtil.SplicingMap(paramHashMap, "&");
            log.debug("doCust_One callJson:" + callJson);

            String doURL = doURL_Domain + "/ae/query-register-info";
            log.debug("doCust_One doURL:" + doURL);

            Map<String, String> headMap = new HashMap<String, String>();
            headMap.put("Content-Type", "application/x-www-form-urlencoded");

            // 执行调用API & 解析返回信息
            String getResult = Util.doHttpPostUseHead(doURL, callJson, "UTF-8", 10000, 0, headMap);
            reJson = JSONObject.fromObject(getResult);
            log.debug("✅doCust_One Result Str:" + reJson);

            String code = KHUtil.GetSFJV(reJson, "code");
            log.debug("doCust_One 解析code:" + code);

            if (code.equals("00000")) {
                JSONObject cust_Json = reJson.getJSONObject("result");
                boolean deal_Res = doDealCustMain(jt, cust_Json);

                if (deal_Res) {
                    reJson = JSONObject.fromObject("{\"code\":\"1\",\"message\":\"同步(补录)单个客户信息完成,结果:成功\"}");
                } else {
                    reJson = JSONObject.fromObject("{\"code\":\"0\",\"message\":\"同步(补录)单个客户信息完成,结果:失败\"}");
                }

            } else {
                log.warn("doCust_One 返回Code异常:" + code);
                reJson = JSONObject.fromObject("{\"code\":\"" + code + "\",\"message\":\"" + KHUtil.GetSFJV(reJson, "error") + "\"}");
            }


        } catch (Exception e) {
            log.error("doCust_One 接口处理异常" + e.getMessage());
            // 失败返回
            reJson = JSONObject.fromObject("{\"code\":\"-1\",\"message\":\"同步(补录)单个客户信息 处理异常\"}");
        }

        return reJson;

    }

    // 同步(补录)全量客户信息
    public static JSONObject doCust_History(JdbcTemplate jt, String inJson) {

        // 初始化 & 调用处理信息
        JSONObject inObject = JSONObject.fromObject(inJson);
        JSONObject reJson = new JSONObject();
        String lastId = "0";
        String pageSize = "20";

        try {

            // 解析调用参数
            String createBeginTime = KHUtil.GetSFJV(inObject, "createBeginTime");
            String createEndTime = KHUtil.GetSFJV(inObject, "createEndTime");

            if (KHUtil.isNull(createBeginTime) || KHUtil.isNull(createEndTime)) {
                log.debug("doCust_History 接口入参为空:" + inObject);
                String outData = "{\"code\":\"-1\",\"message\":\"接口入参为空\"}";
                return JSONObject.fromObject(outData);
            }
            log.debug("doCust_History 解析信息-" + "createBeginTime: " + createBeginTime + "createEndTime: " + createEndTime);

            boolean nextPage = true;
            int loop_Num = 0;
            int succ_Num = 0;
            int fail_Num = 0;
            while (nextPage && loop_Num < 3) {
                loop_Num++;
                String sign_time = String.valueOf(System.currentTimeMillis());
                log.debug("doCust_History 调用信息-" + "sign_time: " + sign_time);

                String finalLastId = lastId;
                HashMap<String, String> paramHashMap = new HashMap<String, String>() {
                    {
                        put("lastId", finalLastId);//初始传0，后续接口中有返回
                        put("pageSize", pageSize);//页码，默认20
                        put("createBeginTime", createBeginTime);
                        put("createEndTime", createEndTime);
                        put("sign_time", sign_time);
                    }
                };
                log.debug("doCust_History paramHashMap：" + paramHashMap);

                //自然排序 升序参数
                String signfront = ThreeDesUtil.sortMap(paramHashMap, appid, appsecret);
                log.debug("doCust_History sign加密MD5前：" + signfront);
                String signafter = Util.getMD5Str(signfront);
                log.debug("doCust_History sign加密MD5后：" + signafter);

                //拼接接口入参
                paramHashMap.put("client_key", appid);
                paramHashMap.put("sign", signafter);

                String callJson = ThreeDesUtil.SplicingMap(paramHashMap, "&");
                log.debug("doCust_History callJson:" + callJson);


                String doURL = doURL_Domain + "/ae/query-register-history";
                log.debug("doCust_History doURL:" + doURL);

                Map<String, String> headMap = new HashMap<String, String>();
                headMap.put("Content-Type", "application/x-www-form-urlencoded");

                String getResult = Util.doHttpPostUseHead(doURL, callJson, "UTF-8", 10000, 0, headMap);
                reJson = JSONObject.fromObject(getResult);
                log.debug("✅doCust_History Result Str:" + reJson);

                String code = KHUtil.GetSFJV(reJson, "code");
                log.debug("doCust_History 解析code:" + code);

                if (code.equals("00000")) {
                    JSONObject res_Json = reJson.getJSONObject("result");
                    nextPage = Boolean.parseBoolean(KHUtil.GetSFJV(res_Json, "nextPage"));
                    lastId = KHUtil.GetSFJV(res_Json, "lastId");
                    JSONArray cust_Arr = res_Json.getJSONArray("dataList");
                    log.debug("ℹdoCust_History 循环控制信息 nextPage:" + nextPage + " lastId:" + lastId);

                    for (int i = 0; i < cust_Arr.size(); i++) {
                        JSONObject cust_Json = cust_Arr.getJSONObject(i);
                        boolean deal_Res = doDealCustMain(jt, cust_Json);

                        if (deal_Res) {
                            succ_Num++;
                        } else {
                            fail_Num++;
                        }

                    }

                } else {
                    log.warn("doCust_History 返回Code异常:" + code);
                    reJson = JSONObject.fromObject("{\"code\":\"" + code + "\",\"message\":\"" + KHUtil.GetSFJV(reJson, "error") + "\"}");
                }

            }
            reJson = JSONObject.fromObject("{\"code\":\"1\",\"message\":\"同步(补录)全量客户信息完成,总调用次数:" + loop_Num + " 成功客户:" + succ_Num + " 失败客户:" + fail_Num + "\"}");

        } catch (Exception e) {
            log.error("doCust_One 接口处理异常" + e.getMessage());
            // 失败返回
            reJson = JSONObject.fromObject("{\"code\":\"-1\",\"message\":\"同步(补录)全量客户信息 处理异常\"}");
        }
        return reJson;

    }

    // 解析Mapn值(此方法增加需要解析的key不存在保护)
    public static String GetMapV(Map inMap, String getKey) {
        String Rev_Value = null;
        try {
            Rev_Value = String.valueOf(inMap.get(getKey));
        } catch (Exception e) {

            Rev_Value = "";
        } finally {
            if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
                Rev_Value = "";
            }
        }
        return Rev_Value;
    }

    // 1-处理核心客户信息Main
    public static boolean doDealCustMain(JdbcTemplate jt, JSONObject cust_Json) {

        log.debug("处理核心客户信息Main cust_Json:" + cust_Json);
        boolean deal_Res = true;

        try {
            // 解析当前客户信息
            String registerstatus = KHUtil.GetSFJV(cust_Json, "registerstatus");//1已开户 2（注册） 3（暂存） 4（审核中）
            String customerid = KHUtil.GetSFJV(cust_Json, "customerid");//华盛号
            String customername = KHUtil.GetSFJV(cust_Json, "customername");//姓名
            String phone = KHUtil.GetSFJV(cust_Json, "phone");//手机号
            String register = KHUtil.GetSFJV(cust_Json, "register");//注册渠道
            String register_id = KHUtil.GetSFJV(cust_Json, "register_id");//注册渠道ID
            String registertime = KHUtil.GetSFJV(cust_Json, "registertime");//注册时间
            String stashtime = KHUtil.GetSFJV(cust_Json, "stashtime");//暂存时间
            String audittime = KHUtil.GetSFJV(cust_Json, "audittime");//审核时间
            String invitertype = KHUtil.GetSFJV(cust_Json, "invitertype");//邀请类型
            String inviterhstno = KHUtil.GetSFJV(cust_Json, "inviterhstno");//邀请人华盛号
            String invitername = KHUtil.GetSFJV(cust_Json, "invitername");//邀请人姓名

            // 手机号脱敏
            String phone_enc = DecryptUtil.encrypt(phone);

            // 转换时间字段信息
            registertime = !KHUtil.isNull(registertime) ? "'" + registertime + "'" : null;
            stashtime = !KHUtil.isNull(stashtime) ? "'" + stashtime + "'" : null;
            audittime = !KHUtil.isNull(audittime) ? "'" + audittime + "'" : null;

            // 检查当前系统中是否存在
            String getCustSQL = "select c.customer_guid,o.objective_guid from customer c left join objective o on c.customer_guid=o.customer_guid and o.map_id='MY48ZX' where 1=1  and c.customer_id=?";
            List<Map<String, Object>> getCustList = jt.queryForList(getCustSQL, customerid);
            log.debug("检查当前系统中是否存在 List:" + getCustList.toString());

            if (getCustList.size() > 0) {
                Map<String, Object> getCustMap = getCustList.get(0);
                String customer_guid = GetMapV(getCustMap, "customer_guid");
                String objective_guid = GetMapV(getCustMap, "objective_guid");
                log.debug("检查当前系统存在客户-customer_guid: " + customer_guid + " objective_guid: " + objective_guid);

                //更新 customer 无objective elitetask 任务
                if (KHUtil.isNull(objective_guid)) {
                    deal_Res = getcust2(jt, customer_guid, registerstatus, customerid, customername, phone, register, register_id, registertime, stashtime, audittime, invitertype, inviterhstno, invitername, phone_enc);

                } else {//更新 customer  有objective elitetask 任务的情况
                    deal_Res = getcust1(jt, customer_guid, registerstatus, customerid, customername, phone, register, register_id, registertime, stashtime, audittime, invitertype, inviterhstno, invitername, phone_enc);
                }

            } else {
                //新增
                deal_Res = getcust(jt, registerstatus, customerid, customername, phone, register, register_id, registertime, stashtime, audittime, invitertype, inviterhstno, invitername, phone_enc);
            }

        } catch (Exception e) {
            log.error("调用华盛接口获取客户信息 接口处理异常" + e.getMessage());
            deal_Res = false;
        }

        return deal_Res;
    }

    // 2-1-新增Customer Objective Elitetask
    public static boolean getcust(JdbcTemplate jt, String registerstatus, String customerid, String customername, String phone, String register, String register_id, String registertime, String stashtime, String audittime, String invitertype, String inviterhstno, String invitername, String phone_enc) {

        boolean reJson = true;
        try {

            // 生成相关ID
            String Temp_Guid = KHUtil.getRandomString(31).toUpperCase();
            String Customer_Guid = "CUST_" + Temp_Guid;
            String Objective_Guid = "OBJE_" + Temp_Guid;
            String EliteTask_Guid = "TASK_" + Temp_Guid;
            log.debug("Customer_Guid:    " + Customer_Guid);

            String[] custTaskDealSQL = new String[3];
            custTaskDealSQL[0] = "Insert Into Customer" + "  (Customer_Guid," + "   Customer_Id," + "   stringfield9," + "   Customername," + "   Mobile," + "   Mobile_enc," + "   Stringfield13," + "   sq_9," + "   Stringfield7," + "   Sq_5," + "   Sq_6," + "   Sq_7," + "   registerstatus," + "   stashtime," + "   audittime," + "   Createdby," + "   Createddate)" + "  Select '" + Customer_Guid + "'," + "         '" + customerid + "'," + "         '" + customerid + "'," + "         '" + customername + "'," + "         '***'," + "         '" + phone_enc + "'," + "         '" + register + "'," + "         '" + register_id + "'," + "         " + registertime + "," + "         '" + inviterhstno + "'," + "         '" + invitername + "'," + "         '" + invitertype + "'," + "         '" + registerstatus + "'," + "         " + stashtime + "," + "         " + audittime + "," + "         'SELITE'," + "         Now()" + "    From dual";

            // 插入Objective表
            custTaskDealSQL[1] = "Insert Into Objective" + "  (Objective_Guid," + "   Objectivetype_Id," + "   Handleby_Id," + "   Handlegroup_Id," + "   Priority_Id," + "   Expireddate," + "   Customer_Guid," + "   Objectivestatus," + "   Iscontact," + "   Trytimes," + "   Successfulcontacttimes," + "   Createdby," + "   Createddate," + "   Obstatus," + "   Failure_Attempt," + "   Contact_Customer_Guid," + "   Passflag," + "   Lastassigndate," + "   Failstatus," + "   Successstatus," + "   Owner," + "   Workorderframe_Id," + "   Category," + "   Forecastdate," + "   Workorderid," + "   Workordertype1," + "   Workordertype2," + "   Workordertype3," + "   Workordertype4," + "   Objectivesubstatus," + "   Map_Id," + "   Curstep_Id_Map," + "   Max_Attempt," + "   Nocontacttry," + "   Allocation_Pool," + "   Appointment,distributionnumber)" + "Values" + "  ('" + Objective_Guid + "'," + "   'RE0TX1'," + "   null," + "   null," + "   'NORMAL'," + "   Date_Add(Now(), Interval 1 Day)," + "   '" + Customer_Guid + "'," + "   'OPEN'," + "   0," + "   0," + "   0," + "   'SELITE'," + "   Now()," + "   'OPEN'," + "   999," + "   ''," + "   0," + "   Null," + "   '0'," + "   '0'," + "   ''," + "   'MY48ZX'," + "   'CASE'," + "   '2021-04-25 17:59:35'," + "   Concat('HS', Date_Format(Now(), '%Y%m%d%H'), '-', Lpad(Floor(Rand() * 10000), 4, '0'))," + "   'QL800E'," + "   'O7JIUV'," + "   ''," + "   ''," + "   ''," + "   'MY48ZX'," + "   'ONA0KD'," + "   0," + "   0," + "   0," + "   0,0)";

            // 插入EliteTask表
            custTaskDealSQL[2] = "Insert Into Elitetask" + "  (Elitetask_Guid," + "   Objective_Guid," + "   Objectivetype_Id," + "   Expectstarttime," + "   Expectendtime," + "   Obstatus," + "   Recordstatus," + "   Attempt," + "   Max_Attempt," + "   Handleby_Id," + "   Handlegroup_Id," + "   Createdby," + "   Createddate," + "   Failure_Attempt," + "   Comments," + "   Customer_Guid," + "   Localtrycount," + "   Lastassigndate," + "   Workorderframe_Id," + "   Curstepstatus," + "   Curstep_Id," + "   Stepforecastdate," + "   Curstep_Id_Map," + "   Map_Id," + "   Objectivesubstatus," + "   Elitetaskstatus," + "   Obflag,Maintaskstep_Id_Map)" + "Values" + "  ('" + EliteTask_Guid + "'," + "   '" + Objective_Guid + "'," + "   'RE0TX1'," + "   Now()," + "   Date_Add(Now(), Interval 3 Day)," + "   'OPEN'," + "   0," + "   1," + "   999," + "   null," + "   null," + "   'SELITE'," + "   Now()," + "   999," + "   ''," + "   '" + Customer_Guid + "'," + "   0," + "   Now()," + "   ''," + "   'OPEN'," + "   'ONA0KD'," + "   Now()," + "   'ONA0KD'," + "   'MY48ZX'," + "   ''," + "   'OPEN'," + "   1,'ONA0KD')";

            log.debug("客户入库处理SQL：" + Arrays.toString(custTaskDealSQL));
            int[] batchSQLResult = jt.batchUpdate(custTaskDealSQL);
            log.debug("客户入库处理SQL返回结果：" + Arrays.toString(batchSQLResult));

        } catch (JSONException e) {
            log.error("接口处理异常" + e.getMessage());
            reJson = false;
        }

        return reJson;
    }

    // 2-2-更新Customer
    public static boolean getcust1(JdbcTemplate jt, String Customer_Guid, String registerstatus, String customerid, String customername, String phone, String register, String register_id, String registertime, String stashtime, String audittime, String invitertype, String inviterhstno, String invitername, String phone_enc) {

        boolean reJson = true;

        try {

            String[] custTaskDealSQL = new String[1];

            custTaskDealSQL[0] = "update Customer set" + "   Customer_Id= case when '" + customerid + "' is null or '" + customerid + "' ='' then Customer_Id else '" + customerid + "' end," + "   Customername=case when '" + customername + "' is null or '" + customername + "' ='' then Customername else '" + customername + "' end ," + "   Mobile='***'," + "   Mobile_enc=case when '" + phone_enc + "' is null or '" + phone_enc + "' ='' then Mobile_enc else '" + phone_enc + "' end ," + "   Stringfield13=case when '" + register + "' is null or '" + register + "' ='' then Stringfield13 else '" + register + "' end," + "   sq_9=case when '" + register_id + "' is null or '" + register_id + "' ='' then sq_9 else '" + register_id + "' end," + "   Stringfield7=case when " + registertime + " is null or " + registertime + " ='' then Stringfield7 else " + registertime + " end," + "   Sq_5=case when '" + inviterhstno + "' is null or '" + inviterhstno + "' ='' then Sq_5 else '" + inviterhstno + "' end," + "   Sq_6=case when '" + invitername + "' is null or '" + invitername + "' ='' then Sq_6 else '" + invitername + "' end," + "   Sq_7=case when '" + invitertype + "' is null or '" + invitertype + "' ='' then Sq_7 else '" + invitertype + "' end," + "   registerstatus =case when '" + registerstatus + "'=1 then 1 else '" + registerstatus + "'end," + "   stashtime=case when " + stashtime + " is null or " + stashtime + " ='' then stashtime else " + stashtime + " end," + "   audittime=case when " + audittime + " is null or " + audittime + " ='' then audittime else " + audittime + " end," + "   MODIFIEDBY='SELITE'," + "   MODIFIEDDATE=Now() where Customer_Guid ='" + Customer_Guid + "'";

            log.debug("客户入库处理SQL：" + Arrays.toString(custTaskDealSQL));
            int[] batchSQLResult = jt.batchUpdate(custTaskDealSQL);
            log.debug("客户入库处理SQL返回结果：" + Arrays.toString(batchSQLResult));

        } catch (JSONException e) {
            log.error("接口处理异常" + e.getMessage());
            reJson = false;
        }

        return reJson;
    }

    // 2-3-更新Customer 新增Objective Elitetask
    public static boolean getcust2(JdbcTemplate jt, String Customer_Guid, String registerstatus, String customerid, String customername, String phone, String register, String register_id, String registertime, String stashtime, String audittime, String invitertype, String inviterhstno, String invitername, String phone_enc) {

        boolean reJson = true;

        try {

            // 生成相关ID
            String Temp_Guid = KHUtil.getRandomString(31).toUpperCase();
            String Objective_Guid = "OBJE_" + Temp_Guid;
            String EliteTask_Guid = "TASK_" + Temp_Guid;

            String[] custTaskDealSQL = new String[3];
            custTaskDealSQL[0] = "update Customer set" + "   Customer_Id= case when '" + customerid + "' is null or '" + customerid + "' ='' then Customer_Id else '" + customerid + "' end," + "   Customername=case when '" + customername + "' is null or '" + customername + "' ='' then Customername else '" + customername + "' end ," + "   Mobile='***'," + "   Mobile_enc=case when '" + phone_enc + "' is null or '" + phone_enc + "' ='' then Mobile_enc else '" + phone_enc + "' end ," + "   Stringfield13=case when '" + register + "' is null or '" + register + "' ='' then Stringfield13 else '" + register + "' end," + "   sq_9=case when '" + register_id + "' is null or '" + register_id + "' ='' then sq_9 else '" + register_id + "' end," + "   Stringfield7=case when " + registertime + " is null or " + registertime + " ='' then Stringfield7 else " + registertime + " end," + "   Sq_5=case when '" + inviterhstno + "' is null or '" + inviterhstno + "' ='' then Sq_5 else '" + inviterhstno + "' end," + "   Sq_6=case when '" + invitername + "' is null or '" + invitername + "' ='' then Sq_6 else '" + invitername + "' end," + "   Sq_7=case when '" + invitertype + "' is null or '" + invitertype + "' ='' then Sq_7 else '" + invitertype + "' end," + "   registerstatus =case when '" + registerstatus + "'=1 then registerstatus else '" + registerstatus + "'end," + "   stashtime=case when " + stashtime + " is null or " + stashtime + " ='' then stashtime else " + stashtime + " end," + "   audittime=case when " + audittime + " is null or " + audittime + " ='' then audittime else " + audittime + " end," + "   MODIFIEDBY='SELITE'," + "   MODIFIEDDATE=Now() where Customer_Guid ='" + Customer_Guid + "'";

            // 插入Objective表
            custTaskDealSQL[1] = "Insert Into Objective" + "  (Objective_Guid," + "   Objectivetype_Id," + "   Handleby_Id," + "   Handlegroup_Id," + "   Priority_Id," + "   Expireddate," + "   Customer_Guid," + "   Objectivestatus," + "   Iscontact," + "   Trytimes," + "   Successfulcontacttimes," + "   Createdby," + "   Createddate," + "   Obstatus," + "   Failure_Attempt," + "   Contact_Customer_Guid," + "   Passflag," + "   Lastassigndate," + "   Failstatus," + "   Successstatus," + "   Owner," + "   Workorderframe_Id," + "   Category," + "   Forecastdate," + "   Workorderid," + "   Workordertype1," + "   Workordertype2," + "   Workordertype3," + "   Workordertype4," + "   Objectivesubstatus," + "   Map_Id," + "   Curstep_Id_Map," + "   Max_Attempt," + "   Nocontacttry," + "   Allocation_Pool," + "   Appointment,distributionnumber)" + "Values" + "  ('" + Objective_Guid + "'," + "   'RE0TX1'," + "   null," + "   null," + "   'NORMAL'," + "   Date_Add(Now(), Interval 1 Day)," + "   '" + Customer_Guid + "'," + "   'OPEN'," + "   0," + "   0," + "   0," + "   'SELITE'," + "   Now()," + "   'OPEN'," + "   999," + "   ''," + "   0," + "   Null," + "   '0'," + "   '0'," + "   ''," + "   'MY48ZX'," + "   'CASE'," + "   '2021-04-25 17:59:35'," + "   Concat('HS', Date_Format(Now(), '%Y%m%d%H'), '-', Lpad(Floor(Rand() * 10000), 4, '0'))," + "   'QL800E'," + "   'O7JIUV'," + "   ''," + "   ''," + "   ''," + "   'MY48ZX'," + "   'ONA0KD'," + "   0," + "   0," + "   0," + "   0,0)";

            // 插入EliteTask表
            custTaskDealSQL[2] = "Insert Into Elitetask" + "  (Elitetask_Guid," + "   Objective_Guid," + "   Objectivetype_Id," + "   Expectstarttime," + "   Expectendtime," + "   Obstatus," + "   Recordstatus," + "   Attempt," + "   Max_Attempt," + "   Handleby_Id," + "   Handlegroup_Id," + "   Createdby," + "   Createddate," + "   Failure_Attempt," + "   Comments," + "   Customer_Guid," + "   Localtrycount," + "   Lastassigndate," + "   Workorderframe_Id," + "   Curstepstatus," + "   Curstep_Id," + "   Stepforecastdate," + "   Curstep_Id_Map," + "   Map_Id," + "   Objectivesubstatus," + "   Elitetaskstatus," + "   Obflag,Maintaskstep_Id_Map)" + "Values" + "  ('" + EliteTask_Guid + "'," + "   '" + Objective_Guid + "'," + "   'RE0TX1'," + "   Now()," + "   Date_Add(Now(), Interval 3 Day)," + "   'OPEN'," + "   0," + "   1," + "   999," + "   null," + "   null," + "   'SELITE'," + "   Now()," + "   999," + "   ''," + "   '" + Customer_Guid + "'," + "   0," + "   Now()," + "   ''," + "   'OPEN'," + "   'ONA0KD'," + "   Now()," + "   'ONA0KD'," + "   'MY48ZX'," + "   ''," + "   'OPEN'," + "   1,'ONA0KD')";

            log.debug("客户入库处理SQL：" + custTaskDealSQL);
            int[] batchSQLResult = jt.batchUpdate(custTaskDealSQL);
            log.debug("客户入库处理SQL返回结果：" + batchSQLResult.toString());

        } catch (JSONException e) {
            log.error("接口处理异常" + e.getMessage());
            reJson = false;
        }

        return reJson;
    }

}